package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.*;
import com.itheima.advantagesup.entity.SysUser;
import com.itheima.advantagesup.service.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * SysUserController
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/7/26 14:57
 */
@RestController
@RequestMapping("/sys_user")
@RequiredArgsConstructor
@Slf4j
public class SysUserController {

    @Autowired
    private final SysUserService sysUserService;

    /**
     * 创建
     *
     * @param sysUserCreateDTO 系统用户创建dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/add")
    public R<?> create(@RequestBody SysUserCreateDTO sysUserCreateDTO){
        sysUserService.create(sysUserCreateDTO);
        return R.success();
    }

    /**
     * 删除通过id
     *
     * @param sysUserDelDTO 系统用户del dto
     * @return {@link R}<{@link ?}>
     */
    @GetMapping("/del")
    public R<?> deleteById(SysUserDelDTO sysUserDelDTO){
        sysUserService.deleteById(sysUserDelDTO);
        return R.success();
    }

    /**
     * 页面
     *
     * @param sysUserPageDTO 系统用户页面dto
     * @return {@link R}<{@link PageBean}>
     */
    @GetMapping("list")
    public R<PageBean> page(SysUserPageDTO sysUserPageDTO){
        PageBean pageBean =sysUserService.page(sysUserPageDTO);
        return R.success(pageBean);
    }

    /**
     * 查询通过id
     *
     * @param sysUserInfoDTO 系统用户信息dto
     * @return {@link R}<{@link SysUser}>
     */
    @GetMapping("/rowInfo")
    public R<SysUser> queryById(SysUserInfoDTO sysUserInfoDTO){
        SysUser sysUser = sysUserService.queryById(sysUserInfoDTO);
        return R.success(sysUser);
    }

    /**
     * 更新通过id
     *
     * @param sysUserUpdateDTO 系统用户更新dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> updateById(@RequestBody SysUserUpdateDTO sysUserUpdateDTO){
        sysUserService.updateById(sysUserUpdateDTO);
        return R.success();
    }
}
